var pageii = null;
var grid = null;
$(function() {

	grid = lyGrid({
		pagId : 'paging',
		l_column : [{
			colkey : "userName",
			name : "姓名"
		}, {
			colkey : "accountName",
			name : "用户名"
		}, {
			colkey : "locked",
			name : "状态",
			renderData : function(rowindex,data, rowdata, column) {
				if(data==1){
					return "<span style='color:green;'>可用</span>";
				}else{
					return "<span style='color:red;'>已锁定</span>";
				}
			}
		}, {
			colkey : "createTime",
			name : "创建时间",
			renderData : function(rowindex,data, rowdata, column) {
				return new Date(data).format("yyyy-MM-dd hh:mm:ss");
			}
		},{
			colkey : "pname",
			name : "岗位"
		}],
		jsonUrl : rootPath + '/internalstaff/user_findByPage.shtml',
		dymCol:true,
		checkbox : true,
		serNumber : false
	});
	$("#addUser").click("click", function() {
		addAccount();
	});
	$("#clientrelation").click("click", function() {
		clientrelationAccount();
	});
	$("#editUser").click("click", function() {
		editAccount();
	});
	$("#delOrder").click("click", function() {
		delAccount();
	});
	$("#search").click("click", function() {// 绑定查询按扭
		var searchParams = $("#searchForm").serializeJson();
		grid.setOptions({
			data : searchParams
		});
	});
	
});

function clientrelationAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1) {
		layer.msg("只能选中一个");
		return;
	}
	if(cbox == ""){
		layer.msg("需要选择一个");
		return;
	}
	pageii = layer.open({
		title : "客户分配",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/internalstaff/client_UI.shtml?id=' + cbox
	});
}


function orderplannerAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1) {
		layer.msg("只能选中一个");
		return;
	}
	if(cbox == ""){
		layer.msg("需要选择一个");
		return;
	}
	pageii = layer.open({
		title : "查看计划",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/material/order_planner.shtml?id=' + cbox
	});
}
function editAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1) {
		layer.msg("只能选中一个");
		return;
	}
	if(cbox == ""){
		layer.msg("需要选择一个");
		return;
	}
	pageii = layer.open({
		title : "编辑员工信息",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/internalstaff/user_edit.shtml?id=' + cbox
	});
}
function addAccount() {
	pageii = layer.open({
		title : "新增用户",
		type : 2,
		area : [ "600px", "100%" ],
		content : rootPath + '/internalstaff/user_add.shtml'
	});
}
function delAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/order/order_deleteEntity.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}
	});
}
